var Main = {
	data() {
		return {
			alltaskoptions: [{
				label: '主要',
				alltaskoption: [{
					value: 'all',
					label: '全部数据'
				}, {
					value: 'richeng',
					label: '日程'
				}]
			}, {
				label: '代办',
				alltaskoption: [{
					value: 'one',
					label: '待办任务'
				}, {
					value: 'two',
					label: '待办任务-未结束'
				}, {
					value: 'three',
					label: '待办任务-已结束'
				}, {
					value: 'four',
					label: '待办任务-取消'
				}, {
					value: 'five',
					label: '待办任务-超期'
				}]
			}],
			alltaskinfor: '',
			tasktheme: ''
		}

	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app1')


/*
 * -----------------------------------------------------------------------------------------------
 * -----------------------------------------------------------------------------------------------
 */


/* 遮罩层 */
var Main = {
	data() {
		return {
			formLabelWidth: "230px",
			customer:[],
			customers:[],
			allcomcustmanid:[],
			allcomcustmanids:[],
			alltaskcontactid:[],
			alltaskcontactids:[],
			alltaskrepairID:[],
			alltaskrepairIDs:[],
			tclassify:[],
			tclassifys:[],
			domanname:[],
			domannames:[],
			taskform: {
				description: '',
				custID: '',
				contID: '',
				repairID: '',
				taskclassity:'',
				taskdate: '',
				doname: ''
			},
			dialogFormVisible: false,
			cumloading:false,
			dialogDelete:false,
			taskrules: {
				description: [{
					required: true,
					message: '必填项',
					trigger: 'change'
				}],
				repairID:[{
					required: true,
					message: '必填项',
					trigger: 'change'
				}],
			},
			/* 日期选择 */
			pickerOptions: {
				disabledDate(time) {
					return time.getTime() < Date.now();
				},
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '明天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周后',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}]
			},
		};
	},
	methods: {
		loadAll() {
			return [{
					"value": "三全鲜食（北新泾店）",
					"address": "长宁区新渔路144号"
				},
				{
					"value": "浏阳蒸菜",
					"address": "天山西路430号"
				},
				{
					"value": "红辣椒麻辣烫",
					"address": "上海市长宁区天山西路492号"
				},
				{
					"value": "阳阳麻辣烫",
					"address": "天山西路389号"
				},
			];
		},
		//清除已选内容重选
		 comcustidto(){
			var _this=this;
			_this.customer=_this.customers;
			//清空联系人和维修单
			_this.taskform.contID='';
			_this.taskform.repairID='';
		},
		//获取数据
		getNew(){
			var _this=this;
			this.dialogFormVisible=true;
			axios.post("/aftersale/chooseTaskOptions",
					//参数转换
//					Qs.stringify(this.taskform, {
//						arrayFormat: 'brackets'
//					})
					//id:
					//ajax请求成功的回调函数
				).then(function(v) {
					console.log("回调成功，获取了服务器端返回的值v");
					console.log(v);
					//获取客户
					_this.customers= v.data.comcustid.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.customer=_this.customers;
					//获取任务分类
					_this.tclassifys= v.data.taskclassity.map(item => {
						return { value: item.dictID, label: item.dictName };
					});
					_this.tclassify=_this.tclassifys;
					//获取任务执行人
					_this.domannames= v.data.doname.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.domanname=_this.domannames;
					
				})/*.catch(function() {
					alert("出错了");
				})*/;
		},	
		//加载界面客户
		cumremoteMethod(query) {
			var _this=this;
		      if (query !== '') {
		        this.cumloading = true;
		        setTimeout(() => {
		          this.cumloading = false;
		          this.customer = _this.customers.filter(item => {
		            return item.label.toLowerCase()
		              .indexOf(query.toLowerCase()) > -1;
		          });
		        }, 200);
		      } else {
		        this.uosign = [];
		      }
		    },
	   
		//选择客户查询对应的联系人和维修工单
		selectOnechange(){
			 var _this=this;
			 console.log(_this);
			 axios.post("/aftersale/custToconfortask",
			Qs.stringify({
			'custid':_this.taskform.custID,
			'repaireID':_this.taskform.repairID
			}
			,{arrayFormat: 'brackets'})
			).then(function(v){					          				
			console.log("回调成功，获取了服务器端返回的值v");
			console.log(v.data);
			_this.alltaskcontactid= v.data.contID.map(item => {
				return { value: item.ID, label: item.name };
			});
			_this.alltaskrepairID= v.data.repaireID.map(item => {
				return { value: item.ID, label: item.roname };
			}); 
			//_this.orderes
			})/*.catch(function(){
			alert("信息出错了");
			})*/;					
		},
		//加载联系人
		comtaskcontactidMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alltaskcontactid = _this.alltaskcontactids.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载维修工单
		comrepairIDMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alltaskrepairID = _this.alltaskrepairIDs.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载任务分类
		taskclassifyMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.tclassify = _this.tclassifys.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载任务执行人
		domannameMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.domanname = _this.domannames.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
			
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		submitForm(taskform) {
			//验证方法
			//alert("添加！");
			var _this=this;
			this.$refs[taskform].validate((valid) => {
				if (valid) {
					//post提交数据
					axios.post("/aftersale/addOnetask",
						//参数转换
						Qs.stringify(this.taskform, {
							arrayFormat: 'brackets'
						})
						//id:
						//ajax请求成功的回调函数
					).then(function(v) {
						console.log("回调成功，获取了服务器端返回的值v");
						console.log(v);
						  _this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加成功!',
							duration:3000,
							center: true
						});
		           		//延时两秒刷新
		           		setTimeout(function (){
		           			window.location.href = '/aftersale/task';
		           		}, 2000);
					}).catch(function() {
						//alert("出错了");
						_this.$message({
		           			showClose: true,
							type: 'success',
							message: '添加失败!',
							duration:3000,
							center: true
						});
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		}
	}
}

var Ctor = Vue.extend(Main)
new Ctor().$mount('#app2')


/*
 * -----------------------------------------------------------------------------------------------
 * -----------------------------------------------------------------------------------------------
 */


/*  表单  */
var Main = {
	data() {
		return {
			tasktable:tasktables,
			customer:[],
			customers:[],
			allcomcustmanid:[],
			allcomcustmanids:[],
			alltaskcontactid:[],
			alltaskcontactids:[],
			alltaskrepairID:[],
			alltaskrepairIDs:[],
			tclassify:[],
			tclassifys:[],
			domanname:[],
			domannames:[],
			/*tasktable: [{
				ID: '20161123',
				description: '改版测试',
				taskstatue: '执行中',
				taskpriority: '',
				custname: '张三',
				taskdate: '',
				taskdoman: 'rose'
			}, {
				ID: '20161123',
				description: '改版测试',
				taskstatue: '执行中',
				taskpriority: '',
				custname: '张三',
				taskdate: '',
				taskdoman: 'rose'
			}, {
				ID: '20161123',
				description: '改版测试',
				taskstatue: '执行中',
				taskpriority: '',
				custname: '张三',
				taskdate: '',
				taskdoman: 'rose'
			}, {
				ID: '20161123',
				description: '改版测试',
				taskstatue: '执行中',
				taskpriority: '',
				custname: '张三',
				taskdate: '',
				taskdoman: 'rose'
			}],*/
			/*currentPage1: 5,
			currentPage2: 5,
			currentPage3: 5,
			currentPage4: 4,*/
			pages: pageinfo,
			currentPage4: pageinfo.pageNum,
			multipleSelection: [],
			formLabelWidth: "230px",
			taskform: {
				description: '',
				custID: '',
				contID: '',
				status: 1428,
				tasktime:'',
				createdate:new Date(),
				taskclassity:'',
				createMan:'',
				taskdate: '',
				doname: '',
				priority:''
			},
			dialogFormVisible: false,
			dialogDelete:false,
			cumloading:false,
			taskrules: {
				description: [{
					required: true,
					message: '必填项',
					trigger: 'change'
				}]
			},
			/* 日期选择 */
			pickerOptions: {
				disabledDate(time) {
					return time.getTime() < Date.now();
				},
				shortcuts: [{
					text: '今天',
					onClick(picker) {
						picker.$emit('pick', new Date());
					}
				}, {
					text: '明天',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24);
						picker.$emit('pick', date);
					}
				}, {
					text: '一周后',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24 * 7);
						picker.$emit('pick', date);
					}
				}, {
					text: '一个月后',
					onClick(picker) {
						const date = new Date();
						date.setTime(date.getTime() + 3600 * 1000 * 24 * 30);
						picker.$emit('pick', date);
					}
				}]
			}
			
		}
	},
	
	methods: {
		handleClick(row) {
			console.log(row);
		},
		handleSelectionChange(val) {
			this.multipleSelection = val;
		},
		/*handleSizeChange(val) {
			console.log(`每页 ${val} 条`);
		},
		handleCurrentChange(val) {
			console.log(`当前页: ${val}`);
		},*/
		handleSizeChange(val) {
			window.location.href = '/aftersale/task?pageSize=' + val;

		},
		handleCurrentChange(val) {
			window.location.href = '/aftersale/task?pageNum=' + val;
		},
		querySearchAsync(queryString, cb) {
			var restaurants = this.restaurants;
			var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;

			clearTimeout(this.timeout);
			this.timeout = setTimeout(() => {
				cb(results);
			}, 3000 * Math.random());
		}, 
		createStateFilter(queryString) {
			return (state) => {
				return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
			};
		},
		handleSelect(item) {
			console.log(item);
		},
		mounted() {
			this.restaurants = this.loadAll();
		},
		//清除已选内容重选
		 comcustidto(){
			var _this=this;
			_this.customer=_this.customers;
			//清空联系人和维修单
			_this.taskform.contID='';
			_this.taskform.repairID='';
		},
		//获取数据
		getNew(){
			var _this=this;
			this.dialogFormVisible=true;
			axios.post("/aftersale/chooseTaskOptions",
					//参数转换
//					Qs.stringify(this.taskform, {
//						arrayFormat: 'brackets'
//					})
					//id:
					//ajax请求成功的回调函数
				).then(function(v) {
					console.log("回调成功，获取了服务器端返回的值v");
					console.log(v);
					//获取客户
					_this.customers= v.data.comcustid.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.customer=_this.customers;
					//获取任务分类
					_this.tclassifys= v.data.taskclassity.map(item => {
						return { value: item.dictID, label: item.dictName };
					});
					_this.tclassify=_this.tclassifys;
					//获取任务执行人
					_this.domannames= v.data.doname.map(item => {
						return { value: item.ID, label: item.name };
					});
					_this.domanname=_this.domannames;
					
				})/*.catch(function() {
					alert("出错了");
				})*/;
		},	
		//更新页面数据
		updatehandleClick(row) {
			var _this = this;
			var id= row;
			console.log(_this);
			axios.post("/aftersale/selectOnetask",
				Qs.stringify( {
			   			'ID':row.ID,
				   },{arrayFormat: 'brackets'}) 
				/* //参数转换
				params:{
					complaintId:row.ID
				} */
				//ajax请求成功的回调函数
			).then(function(v) {
				console.log("回调成功，获取了服务器端返回的值v");
				console.log(v.data);
				//获取客户
				_this.customers= v.data.comcust.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.customer=_this.customers;
				//获取任务分类
				_this.tclassifys= v.data.taskclassity.map(item => {
					return { value: item.dictID, label: item.dictName };
				});
				_this.tclassify=_this.tclassifys;
				//获取任务执行人
				_this.domannames= v.data.doname.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.domanname=_this.domannames;
				//获取联系人
				_this.alltaskcontactids= v.data.contact.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.alltaskcontactid=_this.alltaskcontactids;
				/*//获取维修工单
				_this.alltaskrepairIDs= v.data.repire.map(item => {
					return { value: item.ID, label: item.name };
				});
				_this.alltaskrepairID=_this.alltaskrepairIDs; 	*/			
				//传值
				console.log(v.data.oneTask);
				_this.taskform.ID=v.data.oneTask.ID;
				_this.taskform.description=v.data.oneTask.description;
				_this.taskform.custID=v.data.oneTask.custid;
				_this.taskform.contID=v.data.oneTask.conid;
				_this.taskform.status=v.data.oneTask.status;
				_this.taskform.tasktime=v.data.oneTask.tasktime;
				_this.taskform.taskdate=v.data.oneTask.taskdate;
				_this.taskform.createdate=v.data.oneTask.createDate;
				_this.taskform.createMan=v.date.oneTask.manID;
				_this.taskform.taskclassity=v.data.oneTask.classity;
				_this.taskform.doname=v.data.oneTask.manID;
				_this.taskform.priority=v.data.oneTask.priority;
				
			})/* .catch(function() {
				alert("出错了");
			} )*/;
			//this.selectOnechange();
			this.dialogFormVisible = true;
		},
		//加载界面客户
		cumremoteMethod(query) {
			var _this=this;
		      if (query !== '') {
		        this.cumloading = true;
		        setTimeout(() => {
		          this.cumloading = false;
		          this.customer = _this.customers.filter(item => {
		            return item.label.toLowerCase()
		              .indexOf(query.toLowerCase()) > -1;
		          });
		        }, 200);
		      } else {
		        this.uosign = [];
		      }
		    },
	   
		//选择客户查询对应的联系人和维修工单
		selectOnechange(){
			 var _this=this;
			 console.log(_this);
			 axios.post("/aftersale/custToconfortask",
			Qs.stringify({
			'custid':_this.taskform.custID,
			'repaireID':_this.taskform.repairID
			}
			,{arrayFormat: 'brackets'})
			).then(function(v){					          				
			console.log("回调成功，获取了服务器端返回的值v");
			console.log(v.data);
			_this.alltaskcontactid= v.data.contID.map(item => {
				return { value: item.ID, label: item.name };
			});
			_this.alltaskrepairID= v.data.repaireID.map(item => {
				return { value: item.ID, label: item.roname };
			}); 
			//_this.orderes
			})/*.catch(function(){
			alert("信息出错了");
			})*/;					
		},
		//加载联系人
		comtaskcontactidMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alltaskcontactid = _this.alltaskcontactids.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载维修工单
		comrepairIDMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.alltaskrepairID = _this.alltaskrepairIDs.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载任务分类
		taskclassifyMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.tclassify = _this.tclassifys.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//加载任务执行人
		domannameMethod(query) {
			var _this=this;
			if (query !== '') {
				this.cumloading = true;
				setTimeout(() => {
					this.cumloading = false;
					this.domanname = _this.domannames.filter(item => {
						return item.label.toLowerCase()
						.indexOf(query.toLowerCase()) > -1;
					});
				}, 200);
			} else {
				this.uosign = [];
			}
		},
		//提交表单
		submitForm(taskform) {
			//验证方法
			//alert("修改！");
			var _this=this;
			this.$refs[taskform].validate((valid) => {
				if (valid) {
					//post提交数据
					axios.post("/aftersale/updateOnetask",
						//参数转换
						Qs.stringify(this.taskform, {
							arrayFormat: 'brackets'
						})
						//id:
						//ajax请求成功的回调函数
					).then(function(v) {
						console.log("回调成功，获取了服务器端返回的值v");
						console.log(v);
						  _this.$message({
		           			showClose: true,
							type: 'success',
							message: '修改成功!',
							duration:3000,
							center: true
						});
		           		//延时两秒刷新
		           		setTimeout(function (){
		           			window.location.href = '/aftersale/task';
		           		}, 2000);
					}).catch(function() {
						//alert("出错了");
						_this.$message({
		           			showClose: true,
							type: 'success',
							message: '修改失败!',
							duration:3000,
							center: true
						});
					});
				} else {
					console.log('error submit!!');
					return false;
				}
			});
		},
		resetForm(formName) {
			this.$refs[formName].resetFields();
		},
		
		deletenew(ID){
			this.ID=ID;
			this.dialogDelete=true;
		},
		//删除方法
		Delete(){
			var _this=this;
			axios.get("/aftersale/deleteonetask",
           			//参数转换
           			//Qs.stringify(this.form,{arrayFormat: 'brackets'})
           			//ajax请求成功的回调函数
           			{
						params:{
							ID :_this.ID
						}
           			}
          			).then(function(response){					          				
           			console.log("回调成功，获取了服务器端返回的值v");
           			console.log(response.data);					           		
           		_this.restaurants=response.data;
           		//alert("删除成功！");
           		_this.$message({
           			showClose: true,
					type: 'success',
					message: '删除成功!',
					duration:3000,
					center: true
				});
           		//延时两秒刷新
           		setTimeout(function (){
           			window.location.href = '/aftersale/task';
           		}, 2000);

           	}).catch(function(){
           		//alert("删除失败！");
           		_this.$message({
					type: 'error',
					message: '删除失败!',
					duration:3000,
					center: true
				});
           	});	//这个是数据的初始化
	      },
		/*deletenew() {
			this.$confirm('此操作将删除该条记录, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning',
				center: true
			}).then(() => {
				this.$message({
					type: 'success',
					message: '删除成功!'
				});
			}).catch(() => {
				this.$message({
					type: 'info',
					message: '已取消删除'
				});
			});
		}*/
	    //导出Excel
	      downloadfile(){
	    	  window.location.href ="/aftersale/taskExcelDownloads";
	      }
	}
}
var Ctor = Vue.extend(Main)
new Ctor().$mount('#app3')
